//
//  KSInTransitTableViewCell.swift
//  Supermarket
//
//  Created by Black_Crystal on 2017/9/25.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

protocol ChangeAddressDelegate: NSObjectProtocol {
    func changeAddressCallBack()
}

class KSInTransitTableViewCell: UITableViewCell {
    
    weak var delegate: ChangeAddressDelegate?
    private let hintView = UIView()
    private let hintLabel = UILabel()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        hintView.backgroundColor = UIColor.colorWithHexString(hex: "#FBEFD8")
        self.contentView.addSubview(hintView)
        hintView.snp.makeConstraints { (make) in
            make.top.left.right.equalTo(0)
            make.height.equalTo(40)
        }
        
        let hintImage = UIImageView()
        hintView.addSubview(hintImage)
        hintImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(10)
            make.width.height.equalTo(20)
        }
        
        hintLabel.text = "请尽快拣货 拣货ID：12312321313"
        hintLabel.textColor = UIColor.colorWithHexString(hex: "#EF7D3D")
        hintLabel.font = UIFont.systemFont(ofSize: 14)
        hintView.addSubview(hintLabel)
        hintLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(hintImage.snp.right).offset(10)
        }
        
        let codeLabel = UILabel()
        codeLabel.text = "订单号"
        codeLabel.textColor = KSColor.kColor_3
        codeLabel.font = UIFont.systemFont(ofSize: 16)
        self.contentView.addSubview(codeLabel)
        codeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(hintView.snp.bottom).offset(10)
            make.left.equalTo(10)
            make.width.equalTo(80)
        }
        
        let codeNumberLabel = UILabel()
        codeNumberLabel.text = "1231231231231323"
        codeNumberLabel.textColor = KSColor.kColor_3
        codeNumberLabel.font = UIFont.systemFont(ofSize: 15)
        self.contentView.addSubview(codeNumberLabel)
        codeNumberLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(codeLabel.snp.centerY)
            make.left.equalTo(codeLabel.snp.right).offset(20)
        }
        
        let orderTimeLabel = UILabel()
        orderTimeLabel.text = "下单时间"
        orderTimeLabel.textColor = KSColor.kColor_3
        orderTimeLabel.font = UIFont.systemFont(ofSize: 16)
        self.contentView.addSubview(orderTimeLabel)
        orderTimeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(codeLabel.snp.bottom).offset(20)
            make.left.equalTo(10)
            make.width.equalTo(80)
        }
        
        let orderTimeTxtLabel = UILabel()
        orderTimeTxtLabel.text = "2017-08-08"
        orderTimeTxtLabel.textColor = KSColor.kColor_9
        orderTimeTxtLabel.font = UIFont.systemFont(ofSize: 15)
        self.contentView.addSubview(orderTimeTxtLabel)
        orderTimeTxtLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(orderTimeLabel.snp.centerY)
            make.left.equalTo(orderTimeLabel.snp.right).offset(20)
        }
        
        let grayView = UIView()
        grayView.backgroundColor = KSColor.kColor_line
        self.contentView.addSubview(grayView)
        grayView.snp.makeConstraints { (make) in
            make.top.equalTo(orderTimeLabel.snp.bottom).offset(20)
            make.left.right.equalTo(0)
            make.height.equalTo(20)
        }
        
        let personMsgLabel = UILabel()
        personMsgLabel.text = "收货人信息"
        personMsgLabel.textColor = KSColor.kColor_3
        personMsgLabel.font = UIFont.systemFont(ofSize: 17)
        self.contentView.addSubview(personMsgLabel)
        personMsgLabel.snp.makeConstraints { (make) in
            make.top.equalTo(grayView.snp.bottom).offset(20)
            make.left.equalTo(10)
        }
        
        let changeAdressBtn = UIButton()
        changeAdressBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        changeAdressBtn.setTitle("切换其他地址", for: .normal)
        changeAdressBtn.setTitleColor(UIColor.colorWithHexString(hex: "#709DF3"), for: .normal)
        changeAdressBtn.addTarget(self, action: #selector(changeAddressEvent), for: .touchDown)
        self.contentView.addSubview(changeAdressBtn)
        changeAdressBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-10)
            make.centerY.equalTo(personMsgLabel)
        }
        
        let lineView = UIView()
        lineView.backgroundColor = KSColor.kColor_line
        self.contentView.addSubview(lineView)
        lineView.snp.makeConstraints { (make) in
            make.left.equalTo(10)
            make.right.equalTo(0)
            make.top.equalTo(personMsgLabel.snp.bottom).offset(10)
            make.height.equalTo(1)
        }
        
        let nameLabel = UILabel()
        nameLabel.text = "张志宇 123213123123"
        nameLabel.textColor = KSColor.kColor_3
        nameLabel.font = UIFont.systemFont(ofSize: 15)
        self.contentView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(10)
            make.top.equalTo(lineView.snp.bottom).offset(20)
        }
        
        let addressLabel = UILabel()
        addressLabel.text = "dasdasdasdasdasdasdasddsadasd"
        addressLabel.textColor = KSColor.kColor_3
        addressLabel.font = UIFont.systemFont(ofSize: 15)
        self.contentView.addSubview(addressLabel)
        addressLabel.snp.makeConstraints { (make) in
            make.left.equalTo(10)
            make.top.equalTo(nameLabel.snp.bottom).offset(10)
            make.right.equalTo(-10)
        }
    }
    
    @objc func changeAddressEvent() {
        self.delegate?.changeAddressCallBack()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
